using System;
using NHibernate;

namespace Caramel.NHibernate
{
	public static class RepositoryExtensions
	{
		public static ISession GetSession<T>(this IRepository<T> repository) where T : class
		{
			var nhibernateRepository = repository as NHibernateRepository<T>;

			if (nhibernateRepository == null)
			{
				throw new NotSupportedException("GetSession is only supported for NHibernateRepository type.");
			}

			return nhibernateRepository.Session;
		}
	}
}
